package com.zhj.edu.bo;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Data
public class SecurityUser implements UserDetails {

    //账户对象
    private Account account;

    //角色和权限的集合
    private List<String> roleAndPerms;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        //声明一个存储权限和角色的集合对象
        List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
        for (int i = 0; i < roleAndPerms.size(); i++) {
            //放入集合中
            grantedAuthorities.add(new SimpleGrantedAuthority(roleAndPerms.get(i)));
        }
        return grantedAuthorities;
    }

    @Override
    public String getPassword() {
        return account.getPassword();
    }

    @Override
    public String getUsername() {
        return account.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
